home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2856 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  61 lines

  1. Path: www.gnofn.org!not-for-mail
  2. From: clm01@www.gnofn.org (Christopher L Mayeux)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Keyboard input: C's equivalent to BASIC's Inkey$
  5. Date: 24 Jan 1996 09:30:46 -0600
  6. Organization: Greater New Orleans Free-Net
  7. Distribution: world
  8. Message-ID: <4e5jb6$t81@www.gnofn.org>
  9. References: <Pine.SUN.3.91.960111212844.17033A@suntan> <4dbpe1$47c@news.iag.net> <Pine.A32.3.91.960114210134.59051F-100000@black.weeg.uiowa.edu>
  10. NNTP-Posting-Host: www.gnofn.org
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. The Amorphous Mass (robinson@blue.weeg.uiowa.edu) wrote:
  14. : On 14 Jan 1996, John R Buchan wrote:
  15.  
  16. : > There no ansi or truly portable equivalent.  The c.l.c faq (Frequently
  17. : > Asked Question) list mentions several system specific possiblilties.
  18. : > The list is available for anonymous for from ftfm.mit.edu
  19.  
  20. /* Try adding this function to the list of many... */
  21. /* Originally written for OS-9/6809, but can be so */
  22. /* converted to other platforms by changing all the*/
  23. /* reg.rg_ references to the target system's       */
  24. /*                                                 */
  25. /* Use: inkey(fileno(stdin),character) for keyboard*/
  26.  
  27. #include <stdio.h>
  28. #include <os9.h>
  29.  
  30. inkey(path,text)
  31. int path;
  32. char text[1];
  33. {
  34.  struct registers reg;
  35.  int tester=0;
  36.  strcpy(text,"\0");
  37.  
  38.   reg.rg_a=path;
  39.   reg.rg_b=SS_READY;
  40.   _os9(I_GETSTT,®);
  41.   tester=reg.rg_cc & 1; /* carry bit clear if no incoming byte */
  42.  
  43. if (tester == 1)
  44. {
  45.     strcpy(text,"\0");
  46.     goto quit;
  47. }
  48.  
  49. reg.rg_a=path;
  50. reg.rg_y=0x01;
  51. reg.rg_x=text;
  52. _os9(I_READ,®);
  53.  
  54. quit:
  55. text[1]='\0'; /* return a null character if no keypress */
  56. return text;
  57. }
  58.  
  59. -- 
  60. *
  61.